package br.com.petsis.captcha;

import java.awt.image.BufferedImage;
import java.util.Random;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.captcha.Captcha;
import org.jboss.seam.captcha.CaptchaResponse;
import org.jboss.seam.log.Log;

import com.octo.captcha.service.CaptchaServiceException;

/**
 * Classe respons�vel pelo gera��o da imagem CAPTCHA
 */
/*@Name("org.jboss.seam.captcha.captcha")
@Scope(ScopeType.SESSION)
@AutoCreate
@Install(precedence = Install.APPLICATION)
@BypassInterceptors*/
public class ImageCaptchaGenerator{ //extends Captcha {

	/*private static final long serialVersionUID = -7776062431435902060L;
	private static Random random = new Random(System.currentTimeMillis());

	@Logger
	Log log;

	private Integer id;
	private String respons;

	@Override
	@Create
	public void init() {
		log.info("Iniciando captcha");
		id = random.nextInt(100);
		this.renderChallenge();
	}

	@Override
	public BufferedImage renderChallenge() {
		return Jcaptcha.getInstance().getService().getImageChallengeForID(id.toString());
	}

	@Override
	public boolean validateResponse(String response) {
		boolean valido;
		try{
			valido = Jcaptcha.getInstance().getService().validateResponseForID(id.toString(), response);
			if (!valido) {
				this.init();
			}
		}catch (CaptchaServiceException e) {
			e.printStackTrace();
			valido = false;
		}
		return valido;
	}

	public void reload() {
		init();
	}

	@CaptchaResponse(message = "Codigo da imagem invalido")
	public String getRespons() {
		return respons;
	}

	public void setRespons(String respons) {
		this.respons = respons;
	}

	public Integer getId() {
		return id;
	}
	
	public void setId(Integer id){
		this.id = id;
	}
*/
}
